#!/bin/sh
# - nr_threads
# - duration
# - insert
# - simple1

: "${nr_threads:=1}"
: "${duration:=300}"
: "${insert:=0}"
: "${simple1:=0}"

. $LKP_SRC/lib/reproduce-log.sh
. $LKP_SRC/lib/tests/fixup.sh
. $LKP_SRC/lib/debug.sh

cd "$BENCHMARK_ROOT"/cassandra || die "cassandra database has not been installed yet"

fixup_java_home

export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

echo "waiting for launching cassandra server..."
while ! lsof -i:9042
do
    # Cassandra server usually takes about 15 seconds to launch successfully.
    # Here waiting for 25 seconds to ensure the daemon can be launched successfully before the client tries to connect it.
    sleep 25
done

database="$BENCHMARK_ROOT"/cassandra/tools/cqlstress-example.yaml

log_test ./tools/bin/cassandra-stress user profile="$database" ops\(insert="$insert",simple1="$simple1"\) duration="$duration" -rate threads="$nr_threads"
